//
//  LeaveTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/2/22.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "LeaveTableViewCell.h"

@interface LeaveTableViewCell ()

// 头像
@property(nonatomic,strong)UIImageView *headURL;

// 名字
@property(nonatomic,strong)UILabel *nameLabel;

// 时间
@property(nonatomic,strong)UILabel *timeLabel;

// 请假状态
@property(nonatomic,strong)UILabel *stateLabel;

// 箭头
@property(nonatomic,strong)UIImageView *arrowIcon;

@end

@implementation LeaveTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.headURL.image=[UIImage imageNamed:@"head"];

        self.headURL.hidden=NO;

        self.nameLabel.font=Font_Number(16);

        self.timeLabel.font=Font_Number(14);

        self.stateLabel.font=Font_Number(14);

        self.arrowIcon.hidden=NO;

        self.arrowIcon.image=[UIImage imageNamed:@"arrow"];

        self.backgroundColor=WhiteColor;

        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapEvent)];
        [self addGestureRecognizer:tap];

    }
    return self;
}

-(void)tapEvent
{
    if (_delegate&&[_delegate respondsToSelector:@selector(tapEvent)])
    {
        [_delegate tapEvent];
    }
}

// headURL
-(UIImageView *)headURL
{
    if (!_headURL) {
        _headURL=[[UIImageView alloc]init];
        [self.contentView addSubview:_headURL];
        // 圆角和边框
        ViewBorderRadius(_headURL,kmargin*3,kmargin/kmargin,ClearColor);

        [_headURL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kmargin*6,kmargin*6));
        }];
    }
    return _headURL;
}

// nameLabel
- (UILabel *)nameLabel
{

    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"黄伟海" font:Font_Number(16) textColor:[UIColor blackColor] textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.headURL.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(self);
            make.width.mas_equalTo(APPW/4);
        }];
    }
    return _nameLabel;
}

// timeLabel
- (UILabel *)timeLabel
{

    if (!_timeLabel) {
        _timeLabel=[self getLabelWithText:@"2017-2-24" font:Font_Number(14) textColor:Color999999 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.nameLabel.mas_right).offset(kmargin/2);
            make.centerY.mas_equalTo(self);
            make.width.mas_equalTo(APPW/4);
        }];
    }
    return _timeLabel;
}

// stateLabel
- (UILabel *)stateLabel
{
    if (!_stateLabel) {
        _stateLabel=[self getLabelWithText:@"调休" font:Font_Number(14) textColor:Color999999 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_stateLabel];
        [_stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.right.mas_equalTo(self.arrowIcon.mas_left).offset(-kmargin);
        }];

    }
    return _stateLabel;
}

// arrowIcon
-(UIImageView *)arrowIcon
{
    if (!_arrowIcon) {
        _arrowIcon=[UIImageView new];
        [self.contentView addSubview:_arrowIcon];

        [_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kmargin,kmargin));
        }];
    }
    return _arrowIcon;
}


@end
